package summer.binarysearch;

public class Solution744 {
    public char nextGreatestLetter(char[] letters, char target) {
        int i = 0;
        int j = letters.length - 1;
        while (i <= j) {
            int mid = (i + j) >> 1;
            if (letters[mid] > target) j = mid - 1;
            else i = mid + 1;
        }
        if (i == letters.length) return letters[0];
        return letters[i];
    }
}
